#include "cvideoplayer.h"
#include <QMessageBox>

CVideoPlayer::CVideoPlayer(IVSModel *_ivsModel):
    IVSControllerBase(_ivsModel)
{

}

void CVideoPlayer::run()
{
    if(initialize())
    {
        IplImage* frame = cvQueryFrame(capture);
        char key;
        isRunning = true;
        while(frame && isRunning){
            showMainImage(frame);

            key = cvWaitKey(1000/fps);
            if(key == 'r')
                setupROI();

            frame = cvQueryFrame(capture);
        }
    }else
    {
        QMessageBox::warning(0,
                             "Unable to play the video",
                             "Can not capture from the video source. ",
                             QMessageBox::Ok);
    }
}

void CVideoPlayer::stop()
{
    isRunning = false;
    release();
}

void CVideoPlayer::showMainImage(IplImage *img)
{
    if(ivsModel->VideoPlayerSettings().isEnableROI)
        IVSControllerBase::showMainImage(img);
    else
        cvShowImage(ivsModel->CurrentVideoSource().SourceName(), img);
}
